<h2 class="contentTitle" style="margin-bottom:0px;">添加文章</h2>
<div class="page">
  <div class="pageContent" layouth="31">
    <form method="post" class="pageForm required-validate" onsubmit="return false;" id='article_form'>
      <div class="mypageFormContent" style="clear:both;margin-left:24px;padding:8px 0px;">
        <input type="hidden" name="navTabId" value="article_add" />
        <table>
        <tr>
            <th style="width:80px;">固定链接URL：</th>
            <td style="padding:8px;"><input type="text" name="url" size="30" class="required textInput" /></td>
          </tr>
          <tr>
            <th style="width:80px;">标题：</th>
            <td style="padding:8px;"><input type="text" name="title" size="30" class="required textInput" /></td>
          </tr>
          <tr>
            <th style="width:80px;">title：</th>
            <td style="padding:8px;"><input type="text" name="en_title" size="30" class="textInput" /></td>
          </tr>
		  <tr>
            <th style="width:80px;">标题颜色：</th>
            <td style="padding:8px;position: relative;"><input type="text" id="color" name="color" size="30" class="textInput" value="#000000"/></td>
          </tr>
          <tr>
            <th style="width:80px;">文章分类：</th>
            <td style="padding:8px;">
            <?php foreach($categorys as $c):?>
            <input id="<?php echo 'check',$c->id;?>" value="<?php echo $c->id;?>" type="checkbox" name="category[]" /><label for="<?php echo 'check',$c->id;?>"><?php echo $c->name?></label>
            <?php endforeach;?>
            </td>
          </tr>
          <tr>
            <th style="width:80px;">内容：</th>
            <td style="padding:8px;"><textarea cols="80" name="content" style="width:1000px;height:300px;"></textarea></td>
          </tr>
          <tr>
            <th style="width:80px;">Content：</th>
            <td style="padding:8px;"><textarea cols="80" name="en_content" style="width:1000px;height:300px;"></textarea></td>
          </tr>
          <tr>
            <th style="width:80px;">Tags</th>
            <td style="padding:8px;position: relative;"><input type="text" name="tags" size="30" class="textInput" style="width:500px;" />中英文逗号分隔</td>
          </tr>
          <tr>
            <th style="width:80px;">常用标签</th>
            <td style="padding:8px;position: relative;"><?php foreach($tags as $t):?><a href="#" class="tagbtn"><?php echo $t->tag?></a><?php endforeach;?></td>
          </tr>
          <tr>
            <th style="width:80px;"></th>
            <td><div class="buttonActive"><div class="buttonContent"><button id="submitarticle">&nbsp;&nbsp;提交&nbsp;&nbsp;</button></div></div></td>
          </tr>
        </table>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
$("textarea").xheditor({forcePtag:false,upImgUrl:"/article/uploadimg",upImgExt:"jpg,jpeg,gif,png"});
$("input[name='color']").blur(function(){
	color = $(this).val();
	colorval = color.substring(1,7);
	reversecolor = (parseInt('ffffff',16) - parseInt(colorval,16)).toString(16);
	while(reversecolor.length <6)
	{
		reversecolor = '0' + '' + reversecolor;
	}
	$(this).css({'background-color':'#'+colorval,
		'color':'#'+reversecolor
	});
});
$("input[name='color']").blur();
$("#submitarticle").click(function(){
	if(!$("#article_form").valid()) return false;
	if(typeof(interval)!= 'undefined')
	{
		clearInterval(interval);
	}
	$.ajax({
		type:'POST',
		url:'<?php echo Yii::app()->request->requestUri?>',
		data:$("#article_form").serializeArray(),
		dataType:"json",
		cache: false,
		success: function(data){
			navTabAjaxDone(data);
			},
		error: DWZ.ajaxError
	});
});
$(".tagbtn").click(function(){
	tagbox = $("input[name='tags']");
	if(!tagbox.val())
	{
		tagbox.val($(this).html());
	}
	else
	{
		tagbox.val(tagbox.val()+','+$(this).html());
	}
});
//缓存文章逻辑
if(typeof(interval)!= 'undefined')
{
	clearInterval(interval);
}
savedraft = function(){
	//alert($("textarea[name='content']").val());
	$.cookie('savedraft', $("textarea[name='content']").val(), {expires: 7,domain:'admin.ixuepin.us', path: '/'});
	//alert($.cookie('savedraft'));
}
$("textarea[name='content']").val($.cookie('savedraft'));
interval = setInterval("savedraft()",10000);
</script>